#include <iostream>
#include <string>
#include "mysql.h"

int main()
{
    MYSQL* conn = mysql_init(nullptr);
    // 端口号
    if(nullptr == mysql_real_connect(conn, "127.0.0.1", "http_test", "12345678", "http_test", 3306, nullptr, 0) )
    {
        std::cerr << "connect error!" << std::endl;
        printf("%s\n", mysql_error(conn)); //Access denied for user 'root'@'localhost'
        printf("%d", mysql_errno(conn)); //1698
        return 1;
    }
    std::cerr << "connect success" << std::endl;

    std::string sql = "insert into user (name, passwd) values (\'李四\', \'12345678\')";
    std::cerr << "query : " << sql << std::endl;
    int ret = mysql_query(conn, sql.c_str());

    std::cerr << "result: " << ret << std::endl;
    mysql_close(conn);
}